package com.ics.web.controller.travelstar.controller;

import com.ics.common.annotation.IndexLog;
import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.AjaxResult;
import com.ics.web.controller.travelstar.domain.TiresGoods;
import com.ics.web.controller.travelstar.dto.TiresSearchDTO;
import com.ics.web.controller.travelstar.service.ITbTiresGoodsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 轮胎商品Controller
 *
 * @author ics
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/tires/goods")
public class TbTiresGoodsController extends BaseController {

    @Resource
    private ITbTiresGoodsService tbTiresGoodsService;

    /**
     * 查询轮胎产品列表
     */
    @IndexLog
    @ApiOperation("查询轮胎产品列表")
    @GetMapping("/listPage")
    public AjaxResult listPage(TiresSearchDTO tiresSearchDTO) {
        return AjaxResult.success(tbTiresGoodsService.listPage(tiresSearchDTO));
    }

    /**
     * 查看详情
     */
    @ApiOperation("查看详情")
    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable String id) {
        return AjaxResult.success(tbTiresGoodsService.getById(id));
    }

    /**
     * 保存轮胎产品
     * @param tiresGoods
     * @return
     */
    @ApiOperation("保存轮胎产品")
    @PostMapping("/saveTires")
    public AjaxResult saveTires(@RequestBody TiresGoods tiresGoods) {
        return AjaxResult.success(tbTiresGoodsService.saveOrUpdate(tiresGoods));
    }

    /**
     * 删除产品
     */
    @ApiOperation("删除产品")
    @PostMapping("/remove")
    public AjaxResult remove(@RequestParam String ids) {
        return toAjax(tbTiresGoodsService.removeByIds(Arrays.asList(ids.split(","))));
    }

}
